﻿<UserControl x:Class="Brjnk.GpxExplorer.UI.PaperSizePicker"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:l="clr-namespace:Brjnk.GpxExplorer.Localization"
             xmlns:vr="clr-namespace:Brjnk.GpxExplorer.UI.ValidationRules"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d">
    <Grid Name="mainGrid">
        <Grid.BindingGroup>
            <BindingGroup>
                <BindingGroup.ValidationRules>
                    <vr:PaperSizePickerVr />
                </BindingGroup.ValidationRules>
            </BindingGroup>
        </Grid.BindingGroup>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <RadioButton Name="rbPredefined"
                     Grid.Row="0"
                     Content="{l:Loc paperPickerPredefined}"
                     GroupName="radioGroup"
                     IsChecked="True" />
        <StackPanel Grid.Row="1"
                    Margin="20 0 0 0"
                    IsEnabled="{Binding ElementName=rbPredefined,
                                        Path=IsChecked}">
            <ComboBox ItemsSource="{StaticResource PaperSizes}" SelectedItem="{Binding PredefinedPaper}">
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                            <TextBlock Grid.ColumnSpan="4"
                                       FontWeight="Bold"
                                       Text="{Binding Name}" />
                            <TextBlock Grid.Row="1"
                                       Grid.Column="0"
                                       Text="{l:Loc paperSizeWidth}" />
                            <TextBlock Grid.Row="1"
                                       Grid.Column="1"
                                       Text="{Binding Width,
                                                      Converter={StaticResource DoubleToShortLengthConverter}}" />
                            <TextBlock Grid.Row="1"
                                       Grid.Column="2"
                                       Text="{l:Loc paperSizeHeight}" />
                            <TextBlock Grid.Row="1"
                                       Grid.Column="3"
                                       Text="{Binding Height,
                                                      Converter={StaticResource DoubleToShortLengthConverter}}" />
                        </Grid>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>
            <CheckBox Content="{l:Loc paperSizeLandscape}" IsChecked="{Binding Landscape}" />
        </StackPanel>
        <RadioButton Name="rdCustom"
                     Grid.Row="2"
                     Content="{l:Loc paperPickerCustom}"
                     GroupName="radioGroup"
                     IsChecked="{Binding UseCustomSize}" />
        <Grid Grid.Row="3"
              Margin="20 0 0 0"
              IsEnabled="{Binding ElementName=rdCustom,
                                  Path=IsChecked}">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <TextBlock Text="{l:Loc paperSizeWidth}" />
            <TextBlock Grid.Row="1" Text="{l:Loc paperSizeHeight}" />
            <TextBox Name="txbWidth"
                     Grid.Row="0"
                     Grid.Column="1"
                     Text="{Binding CustomPaperWidth,
                                    Converter={StaticResource ShortLengthConverter}}" />
            <TextBox Name="txbHeight"
                     Grid.Row="1"
                     Grid.Column="1"
                     Text="{Binding CustomPaperHeight,
                                    Converter={StaticResource ShortLengthConverter}}" />
        </Grid>
    </Grid>
</UserControl>